<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('上传文件')" />
	<th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-file-add" th:object="${lkMatterProject}">
            <input name="id" th:field="*{id}" type="hidden">
			<input name="id" th:field="*{projectId}" type="hidden">
			<div class="form-group">	
				<div class="col-sm-10">
					<input type="file" name="fliePath" id="fileToUpload"/> 
				</div>
			</div>
		</form>
	</div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: summernote-js" />
    <script type="text/javascript">
	    $("form-file-add").validate({
            focusCleanup: true
        });
		
		function submitHandler() {
            if ($.validate.form()) {
            	var data = new FormData();
    	        data.append("fileHandler",document.getElementById('fileToUpload').files[0]);
    	        $.ajax({
    	            type: "POST",
					url: ctx + "common/upload",
    	            data: data,
    	            cache: false,
    	            contentType: false,
    	            processData: false,
    	            dataType: 'json',
    	            success: function(result) {
    	                if (result.code == 0) {
    	    				updateMatterProject(result.fileName);
    					} else {
    						$.modal.alertError(result.msg);
    					}
    	            },
    	            error: function(error) {
    	                $.modal.alertWarning("上传失败。");
    	            }
    	        });
            }
        }

        function updateMatterProject(fileName) {
			var data = new FormData();
			data.append("id",$("input[name='id']").val());
            data.append("projectId",$("input[name='projectId']").val());
			data.append("fileName",fileName);
			$.ajax({
				type: "POST",
				url: ctx + "linkong/matterProject/uploadFlie",
				data: data,
				cache: false,
				contentType: false,
				processData: false,
				dataType: 'json',
				success: function(result) {
					if (result.code == 0) {
						$.operate.successCallback(result);
					} else {
						$.modal.alertError(result.msg);
					}
				},
				error: function(error) {
					$.modal.alertWarning("上传失败。");
				}
			});
		}
	</script>
</body>
</html>
